home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / util / sys / meminfo.lha / MemInfo / MemInfo.s < prev    next >
Encoding:
Text File  |  1996-08-17  |  6.1 KB  |  389 lines

  1.  
  2. ; *********************************************************
  3. ; **
  4. ; ** MemInfo - An Avail replacement with added information
  5. ; **
  6. ; ** V1.0 - (14/08/96) by Henri Veisterä
  7. ; **
  8. ; *********************************************************
  9.  
  10.     opt    o+,d-,c+
  11.     
  12.     incdir dh0:devpac/include/
  13.     include exec/memory.i
  14.     include exec/execbase.i
  15.  
  16. CallEXEC MACRO
  17.     move.l    _ExecBase(a4),a6
  18.     jsr    _LVO\1(a6)
  19.     ENDM
  20.  
  21. CallDOS MACRO
  22.     move.l    _DOSBase(a4),a6
  23.     jsr    _LVO\1(a6)
  24.     ENDM
  25.  
  26. ; ** Allocate and initialize work memory
  27.  
  28.     link    a4,#-work_SIZEOF
  29.     move.l    sp,a4
  30.     move.l    #work_SIZEOF/4-1,d0
  31. zip    clr.l    (a4)+
  32.     dbf    d0,zip
  33.     move.l    sp,a4
  34.  
  35. ; ** We need OS 2.0 (V36)
  36.  
  37.     move.l    $4.w,_ExecBase(a4)
  38.     lea    dosname(pc),a1
  39.     moveq    #36,d0
  40.     CallEXEC OpenLibrary
  41.     move.l    d0,_DOSBase(a4)
  42.     bne.b    start
  43.     add.l    #work_SIZEOF,a4
  44.     unlk    a4
  45.     moveq    #20,d0
  46.     rts
  47.  
  48. start    CallDOS Output
  49.     move.l    d0,outfile(a4)
  50.  
  51. ; ** Read in the command line arguments
  52.  
  53.     lea    template(pc),a0
  54.     move.l    a0,d1
  55.     lea    array(a4),a0
  56.     move.l    a0,d2
  57.     moveq    #0,d3
  58.     CallDOS ReadArgs
  59.     tst.l    d0
  60.     beq    cl_dos
  61.     lea    array(a4),a0
  62.     move.l    (a0)+,chip(a4)
  63.     move.l    (a0)+,fast(a4)
  64.     move.l    (a0)+,total(a4)
  65.     move.l    (a0)+,flush(a4)
  66.     move.l    d0,d1
  67.     CallDOS FreeArgs
  68.  
  69. ; ** Act according to given arguments
  70.  
  71.     tst.w    flush(a4)
  72.     beq.b    noflush
  73.  
  74. ; ** FLUSH memory
  75.     
  76.     moveq    #0,d2
  77. allo    move.l    #$7FFFFFF0,d0
  78.     moveq    #1,d1
  79.     CallEXEC AllocVec
  80.     move.l    d0,a1
  81.     CallEXEC FreeVec
  82.     addq.w    #1,d2
  83.     cmp.w    #$A,d2
  84.     bcs.b    allo
  85.  
  86. noflush    tst.w    chip(a4)
  87.     beq.b    nochip
  88.  
  89. ; ** Show TOTAL CHIP or FAST values
  90.  
  91. dofast    moveq    #0,d3
  92.     move.l    _ExecBase(a4),a6
  93.     lea    MemList(a6),a0
  94.     move.l    LH_HEAD(a0),a2
  95. cdoall    cmp.b    #NT_MEMORY,LN_TYPE(a2)
  96.     bne.b    cnext
  97.     tst.w    total(a4)
  98.     bne.b    addit
  99.     move.w    MH_ATTRIBUTES(a2),d0
  100.     tst.w    fast(a4)
  101.     beq.b    tchip
  102.     btst    #MEMB_FAST,d0
  103.     bra.s    test
  104. tchip    btst    #MEMB_CHIP,d0
  105. test    beq.b    cnext
  106. addit    add.l    MH_FREE(a2),d3
  107. cnext    move.l    LN_SUCC(a2),a2
  108.     cmp.l    #0,a2
  109.     bne.b    cdoall
  110.  
  111.     lea    outline2(a4),a5
  112.  
  113.     move.l    d3,d0
  114.     moveq    #2,d1
  115.     bsr    printn
  116.     
  117.     clr.b    (a5)+
  118.     lea    outline2(a4),a0
  119.     bsr    rprint
  120.     bra    cl_dos
  121.  
  122. nochip    tst.w    fast(a4)
  123.     bne.b    dofast
  124.     
  125.     tst.w    total(a4)
  126.     bne.b    dofast
  127.     
  128. ; ** Display the standard output
  129.  
  130.     lea    outline2(a4),a5
  131.  
  132.     lea    header(pc),a0
  133.     bsr    rprint
  134.     
  135. ; ** Go through memory list nodes
  136.  
  137.     move.l    _ExecBase(a4),a6
  138.     lea    MemList(a6),a0
  139.     move.l    LH_HEAD(a0),a2
  140. doall    cmp.b    #NT_MEMORY,LN_TYPE(a2)
  141.     bne    next
  142.     move.l    MH_LOWER(a2),d0
  143.     bsr    printhex
  144.     move.l    MH_UPPER(a2),d0
  145.     bsr    printhex
  146.  
  147.     move.b    LN_PRI(a2),d0
  148.     ext.w    d0
  149.     ext.l    d0
  150.     moveq    #-1,d1
  151.     bsr    printn
  152.  
  153.     move.l    MH_UPPER(a2),d0
  154.     sub.l    MH_LOWER(a2),d0
  155.     asr.l    #8,d0
  156.     asr.l    #2,d0
  157.     moveq    #0,d1
  158.     add.l    d0,maximum(a4)
  159.     bsr    printn
  160.  
  161.     move.l    MH_UPPER(a2),d0
  162.     sub.l    MH_LOWER(a2),d0
  163.     sub.l    MH_FREE(a2),d0
  164.     asr.l    #8,d0
  165.     asr.l    #2,d0
  166.     moveq    #0,d1
  167.     add.l    d0,inuse(a4)
  168.     bsr    printn
  169.     
  170.     move.l    MH_FREE(a2),d0
  171.     asr.l    #8,d0
  172.     asr.l    #2,d0
  173.     moveq    #0,d1
  174.     add.l    d0,free(a4)
  175.     bsr    printn
  176.  
  177.     lea    space(pc),a0
  178.     bsr    print
  179.  
  180.     moveq    #0,d1
  181.     move.l    MH_FIRST(a2),a0
  182. getmax    cmp.l    MC_BYTES(a0),d1
  183.     bge.b    nomax
  184.     move.l    MC_BYTES(a0),d1
  185. nomax    move.l    (a0),a0
  186.     cmp.l    #0,a0
  187.     bne.b    getmax
  188.     move.l    d1,d0
  189.     asr.l    #8,d0
  190.     asr.l    #2,d0
  191.     cmp.l    largest(a4),d0
  192.     blt.b    tunne
  193.     move.l    d0,largest(a4)
  194. tunne    moveq    #0,d1
  195.     bsr    printn
  196.     
  197.     move.w    MH_ATTRIBUTES(a2),d0
  198.     btst    #MEMB_PUBLIC,d0
  199.     beq.b    noze1
  200.     move.b    #'P',(a5)+
  201.     bra.s    yeze1
  202. noze1    move.b    #'-',(a5)+
  203. yeze1    btst    #MEMB_CHIP,d0
  204.     beq.b    noze2
  205.     move.b    #'C',(a5)+
  206.     bra.s    yeze2
  207. noze2    move.b    #'-',(a5)+
  208. yeze2    btst    #MEMB_FAST,d0
  209.     beq.b    noze3
  210.     move.b    #'F',(a5)+
  211.     bra.s    yeze3
  212. noze3    move.b    #'-',(a5)+
  213. yeze3    btst    #MEMB_LOCAL,d0
  214.     beq.b    noze4
  215.     move.b    #'L',(a5)+
  216.     bra.s    yeze4
  217. noze4    move.b    #'-',(a5)+
  218. yeze4    btst    #MEMB_24BITDMA,d0
  219.     beq.b    noze5
  220.     move.b    #'D',(a5)+
  221.     bra.s    yeze5
  222. noze5    move.b    #'-',(a5)+
  223. yeze5    btst    #MEMB_KICK,d0
  224.     beq.b    noze6
  225.     move.b    #'K',(a5)+
  226.     bra.s    yeze6
  227. noze6    move.b    #'-',(a5)+
  228. yeze6    move.b    #' ',(a5)+
  229.  
  230.     move.l    LN_NAME(a2),a0
  231.     bsr.s    print
  232.  
  233.     lea    return(pc),a0
  234.     bsr.s    print
  235.  
  236.     move.b    #0,(a5)+
  237.     lea    outline2(a4),a0
  238.     bsr    rprint
  239.  
  240.     lea    outline2(a4),a5
  241.  
  242. next    move.l    LN_SUCC(a2),a2
  243.     cmp.l    #0,a2
  244.     bne    doall
  245.  
  246. ; ** We are done, print out totals
  247.  
  248.     lea    totall(pc),a0
  249.     bsr.s    print
  250.     moveq    #0,d1
  251.     move.l    maximum(a4),d0
  252.     bsr    printn
  253.     moveq    #0,d1
  254.     move.l    inuse(a4),d0
  255.     bsr    printn
  256.     moveq    #0,d1
  257.     move.l    free(a4),d0
  258.     bsr    printn
  259.     lea    space(pc),a0
  260.     bsr.s    print
  261.     moveq    #0,d1
  262.     move.l    largest(a4),d0
  263.     bsr    printn
  264.     lea    return(pc),a0
  265.     bsr.s    print
  266.     move.b    #0,(a5)+
  267.     lea    outline2(a4),a0
  268.     bsr.s    rprint
  269.  
  270. ; ** Exit the program
  271.     
  272. cl_dos    move.l    _DOSBase(a4),a1
  273.     CallEXEC CloseLibrary
  274.     add.l    #work_SIZEOF,a4
  275.     unlk    a4
  276.     moveq    #0,d0
  277.     rts
  278.  
  279. ; ** Subroutines to print out numbers, hex or fstrings
  280.  
  281. print    move.l    a0,-(sp)
  282. nosep    tst.b    (a0)+
  283.     bne.b    nosep
  284.     sub.l    (sp),a0
  285.     move.l    a0,d3
  286.     subq.l    #2,d3
  287.     cmp.l    #-1,d3
  288.     bgt.b    dsd
  289.     moveq    #0,d3
  290. dsd    move.l    (sp)+,a1
  291.     lea    outline2e(a4),a3
  292. juku    cmp.l    a3,a5
  293.     bgt.b    full
  294.     move.b    (a1)+,(a5)+
  295.     dbf    d3,juku
  296. full    rts
  297.  
  298. rprint    move.l    a0,-(sp)
  299. osep    tst.b    (a0)+
  300.     bne.b    osep
  301.     sub.l    (sp),a0
  302.     move.l    a0,d3
  303.     subq.l    #1,d3
  304.     move.l    (sp)+,d2
  305.     move.l    outfile(a4),d1
  306.     CallDOS Write
  307.     rts
  308.  
  309. printhex
  310.     lea    outline(a4),a0
  311.     addq.l    #8,a0
  312.     moveq    #7,d2
  313.     move.l    d0,d1
  314. allnum    and.l    #$f,d0
  315.     cmp.b    #10,d0
  316.     bcs.b    numba
  317.     sub.b    #10,d0
  318.     add.b    #'A',d0
  319.     bra.b    letta
  320. numba    add.b    #'0',d0
  321. letta    move.b    d0,-(a0)
  322.     ror.l    #4,d1
  323.     move.l    d1,d0
  324.     dbf    d2,allnum
  325.     move.b    #' ',8(a0)
  326.     move.b    #0,9(a0)
  327.     lea    outline(a4),a0
  328.     bsr    print
  329.     rts
  330.     
  331. printn    movem.l    a0-a3,-(sp)
  332.     tst.w    d1
  333.     beq.b    klo
  334.     cmp.l    #2,d1
  335.     bne.b    four
  336.     lea    jlong(pc),a0
  337.     bra.s    lo
  338. four    lea    long(pc),a0
  339.     bra.s    lo
  340. klo    lea    longk(pc),a0
  341. lo    lea    dstream(a4),a1
  342.     move.l    d0,(a1)
  343.     lea    putter(pc),a2
  344.     lea    outline(a4),a3
  345.     CallEXEC RawDoFmt
  346.     lea    outline(a4),a0
  347.     bsr    print
  348.     movem.l    (sp)+,a0-a3
  349.     rts
  350.  
  351. putter    move.b    d0,(a3)+
  352.     rts
  353.  
  354. ; ** Internal vars and buffers used
  355.  
  356.     STRUCTURE workmem,0
  357.         LONG    _DOSBase
  358.         LONG    _ExecBase
  359.         LONG    outfile
  360.         LONG    maximum
  361.         LONG    inuse
  362.         LONG    free
  363.         LONG    largest
  364.         LONG    chip
  365.         LONG    fast
  366.         LONG    total
  367.         LONG    flush
  368.         STRUCT    dstream,2*4
  369.         STRUCT    array,4*4
  370.         STRUCT    outline2,120
  371.         LABEL    outline2e
  372.         STRUCT    outline,12
  373.         LABEL    work_SIZEOF
  374.  
  375. ; ** Internal strings
  376.  
  377. dosname        dc.b    "dos.library",0
  378. jlong        dc.b    "%ld",10,0
  379. long        dc.b    "%4.4ld ",0
  380. longk        dc.b    "%5.5ldk ",0
  381. header        dc.b    "Lower    Upper     Pri    Max In-Use   Free Largest Attrib Name",10,0
  382. totall        dc.b    10,"        total:         ",0
  383. template    dc.b    "CHIP/S,FAST/S,TOTAL/S,FLUSH/S",0
  384. version        dc.b    "$VER: MemInfo 1.0 (15.8.96)",10,13,0
  385. return        dc.b    10,0
  386. space        dc.b    " ",0
  387.     
  388.     end
  389.